repo: Add a private helper to replace a file, honoring fsync policy
authorColin Walters <walters@verbum.org>
Mon, 13 Apr 2015 17:28:02 +0000 (13:28 -0400)
committerColin Walters <walters@verbum.org>
Mon, 13 Apr 2015 17:28:02 +0000 (13:28 -0400)
Extracted from discussion in https://github.com/GNOME/ostree/pull/83

src/libostree/ostree-repo-private.h
src/libostree/ostree-repo-refs.c
src/libostree/ostree-repo.c

index 8b07254cedafe57e9b85428c9af17c88054b6302..ceed471105e82ee6f4a5dbed6b3de5b4282b1ad9 100644 (file)
@@ -126,6 +126,15 @@ _ostree_repo_update_refs (OstreeRepo        *self,
                           GCancellable      *cancellable,
                           GError           **error);
 
+gboolean      
+_ostree_repo_file_replace_contents (OstreeRepo    *self,
+                                    int            dfd,
+                                    const char    *path,
+                                    guint8        *buf,
+                                    gsize          len,
+                                    GCancellable  *cancellable,
+                                    GError       **error);
+
 gboolean      
 _ostree_repo_write_ref (OstreeRepo    *self,
                         const char    *remote,
index a436e0423bec34ef8fe8da4ced17138660acf5aa..ee6db8ac6a8a27d55755eae720fbded3c70dd4f1 100644 (file)
@@ -106,9 +106,8 @@ write_checksum_file_at (OstreeRepo   *self,
     bufnl[l] = '\n';
     bufnl[l+1] = '\0';
 
-    if (!glnx_file_replace_contents_at (dfd, name, (guint8*)bufnl, l + 1,
-                                        self->disable_fsync ? GLNX_FILE_REPLACE_NODATASYNC : GLNX_FILE_REPLACE_DATASYNC_NEW,
-                                        cancellable, error))
+    if (!_ostree_repo_file_replace_contents (self, dfd, name, (guint8*)bufnl, l + 1,
+                                             cancellable, error))
       goto out;
   }
 
index 072ae765519724eeaf6e9e97d7bd5c4549e0f5c8..b27fcce8e4d19d0bc757fdd1c81659a180894f74 100644 (file)
@@ -1502,6 +1502,23 @@ ostree_repo_set_disable_fsync (OstreeRepo    *self,
 }
 
 
+/* Replace the contents of a file, honoring the repository's fsync
+ * policy.
+ */ 
+gboolean      
+_ostree_repo_file_replace_contents (OstreeRepo    *self,
+                                    int            dfd,
+                                    const char    *path,
+                                    guint8        *buf,
+                                    gsize          len,
+                                    GCancellable  *cancellable,
+                                    GError       **error)
+{
+  return glnx_file_replace_contents_at (dfd, path, buf, len,
+                                        self->disable_fsync ? GLNX_FILE_REPLACE_NODATASYNC : GLNX_FILE_REPLACE_DATASYNC_NEW,
+                                        cancellable, error);
+}
+
 /**
  * ostree_repo_get_path:
  * @self: